package ctrdashboard

import (
	"cloud_worm/wormweb/controllers/ctrconfig"
	"cloud_worm/util/uhttp"
)

const (
	AlertAll = iota
	AlertHighRisk
	AlertMiddleRisk
	AlertLowRisk
)

type AlertContentCtr struct {
	ctrconfig.LoginCtr
}

func (a *AlertContentCtr) FirstLayer()  {
	a.Guest()

	type AlertClassCount struct {
		ClassName 		string
		HighRiskCnt 	int
		MiddleRiskCnt  	int
		LowRiskCnt 		int
	}
	total := 11
	classData := make([]AlertClassCount, 0, 11)
	for i := 0; i < total; i++ {
		tmp := AlertClassCount{
			ClassName: "mysql",
			HighRiskCnt: 12,
			MiddleRiskCnt: 3,
			LowRiskCnt: 78,
		}
		classData = append(classData, tmp)
	}
	// TODO：xxx

	data := map[string]interface{}{"total": total, "data": classData}
	a.Data["json"] = uhttp.CreateOkResponse(data)
	a.ServeJSON()
	return
}

func (a *AlertContentCtr) SecondLayer()  {
	if a.Guest() == false {
		return
	}

	type AlertTypeCount struct {
		Name 		string
		HighRiskCnt 	int
		MiddleRiskCnt  	int
		LowRiskCnt 		int
	}
	total := 11
	typeData := make([]AlertTypeCount, 0, 11)
	for i := 0; i < total; i++ {
		tmp := AlertTypeCount{
			Name: "mysql bind 0.0.0.0",
			HighRiskCnt: 12,
			MiddleRiskCnt: 3,
			LowRiskCnt: 78,
		}
		typeData = append(typeData, tmp)
	}
	// TODO：xxx

	data := map[string]interface{}{"total": total, "data": typeData}
	a.Data["json"] = uhttp.CreateOkResponse(data)
	a.ServeJSON()
	return
}

func (a *AlertContentCtr) ThirdLayer()  {
	if a.Guest() == false {
		return
	}

	type AlertHostCount struct {
		IP 			string
		AppName 	string
		Msg 		string
		RiskVal 	int
	}
	total := 11
	hostData := make([]AlertHostCount, 0, 11)
	for i := 0; i < total; i++ {
		tmp := AlertHostCount{
			IP: "10.50.169.214",
			AppName: "mst_baicaotest",
			Msg: "/home/mapp/phoenix-flask/redis-server's redis password is empty , allow Anonymous login!",
			RiskVal: AlertHighRisk,
		}
		hostData = append(hostData, tmp)
	}
	// TODO：xxx

	data := map[string]interface{}{"total": total, "data": hostData}
	a.Data["json"] = uhttp.CreateOkResponse(data)
	a.ServeJSON()
	return
}

func (a *AlertContentCtr) ExportNumberFile()  {
	if a.Guest() == false {
		return
	}

	// 关键信息包括: className, name, risk val, msg, ip, app name

	// TODO:
	fileName := "xxxx"
	a.Ctx.Output.Download(fileName)
	return
}